<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 15-6-1
 * Time: 下午12:44
 */

class money extends shopAdminBase{
    /** @var  MoneyMode */
    protected $moneyMode;
    function __construct() {
        parent::__construct();
        $this->cms->setPageTitle("财务管理");
        $this->cms->setControlFile("shop/money/money_control.json");
        $this->moneyMode=MoneyMode::init();
    }

    function indexTask($page,$orderId){
        $url=WebRouter::init()->getQuestion("orderId={$orderId}&page=");
        $page=$page>=1? $page: 1;
        $countOfPage=20;
        $offset=($page-1)*$countOfPage;
        $user_info=$this->user->getLoginInfo();
        if(isset($orderId)&&!empty($orderId)){
            $r['money_info'][0]=$this->moneyMode->getMoneyInfoByOrderId($orderId);
            $list_total=1;
        }else{
            list($r['money_info'],$list_total)=$this->moneyMode->getList($user_info['id'],'shopSell',$countOfPage,$offset);
        }
        $r['money_info']=is_array($r['money_info'])?$r['money_info']:array();
        $r['pages']=new Page($page,$list_total,$countOfPage);
        $r['pages']->setPageCallback(create_function('$page','return "'.$url.'".$page;'));
        $this->cms->tableScene($r,"shop/money/money_info.php");
    }

    function applyInfoTask($page){
        $url=WebRouter::init()->getQuestion("page=");
        $page=$page>=1? $page: 1;
        $countOfPage=20;
        $offset=($page-1)*$countOfPage;
        $user_info=$this->user->getLoginInfo();
        list($r['money_info'],$money_total)=$this->moneyMode->getCashListByUserId($user_info['id'],$countOfPage,$offset);
        $r['money_info']=is_array($r['money_info'])?$r['money_info']:null;
        $r['pages']=new Page($page,$money_total,$countOfPage);
        $r['pages']->setPageCallback(create_function('$page','return "'.$url.'".$page;'));
        $this->cms->tableScene($r,"shop/money/money.php");
    }

    function applyTask(){
        $r['apply']=$this->moneyMode->getTypeAndNum($this->user->getLoginId());
        $this->cms->formScene($r,"shop/money/money_apply.php");
    }

    function applySubmitTask($money,$account_type,$acount_no){
        $user_info=$this->user->getLoginInfo();
        $user_id=$user_info['id'];
        if($this->moneyMode->applyCash($user_id,$money,$account_type,$acount_no)){
            $r['url']=WebRouter::init()->getPage("money","index");
            $r['message']="提现申请已提交，等待审核";
        }else{
            $r['message']="申请失败，请重试！";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }
} 